package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.StreamMQ8801;
import com.atguigu.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author zhaoyuqiang
 * @create 2022/4/24 8:01
 * @description 服务层绑定到消息中间件上
 */
@EnableBinding(Source.class)
public class MessageProvider implements IMessageProvider {

    final private MessageChannel output;

    @Autowired
    public MessageProvider(MessageChannel output) {
        this.output = output;
    }

    @Override
    public void send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*****serial: "  +serial);
    }
}
